<?php ?>
<div class="row-fluid">
<div class="span8">

<header>Module and Features</header>
<div class="accordion" id="accordion">
<?php foreach($modules as $module) {?>

  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse<?= $module->id?>">
       <span class="span2"><?= $module->name?></span>
       <span class="span8 muted"><?= $module->description?></span>
       <span class="span2">Rs. <?= $module->price?></span>
       <div class="clearfix"></div>
      </a>
    </div>
    <div id="collapse<?= $module->id?>" class="accordion-body collapse">
      <div class="accordion-inner">
      <strong>Features</strong>
      <ul>
      <?php foreach($this->proposal_model->get_features_by_module($module->id) as $features ) { ?>
	  <li><?= $features->name?></li>
	  <?php }?>
      </ul>
      </div>
    </div>
  </div>

<?php }?>
</div>

</div>
<div class="span4">
<header>Create Module</header>
<table width="100%" class="">
  <tr>
    <td>Name</td>
    <td><input type="text" name="name" class="module_name" /></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><textarea class="module_desc"></textarea></td>
  </tr>
  <tr>
    <td>Price</td>
    <td>
    <div class="input-prepend">
  <span class="add-on">Rs</span>
  <input class="span6 module_price" id="prependedInput" type="text" placeholder="price">
</div>
    </td>
  </tr>
  <tr>
    <td>Type</td>
    <td><input type="text" class="module_type" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><button class="btn btn-success" id="create-module">Create Module</button></td>
  </tr>
</table>


<header>Create Features</header>
<table width="100%">
  <tr>
    <td>Name</td>
    <td><input type="text" name="name" class="feature_name" /></td>
  </tr>
  <tr>
    <td>Description</td>
    <td><textarea class="feature_desc"></textarea></td>
  </tr>
  <tr>
    <td>Price</td>
    <td>
    <div class="input-prepend">
  <span class="add-on">Rs</span>
  <input  id="prependedInput" type="text" placeholder="price" class="feature_price">
</div>
    </td>
  </tr>
  <tr>
    <td>Module type</td>
    <td>
    <select class="feature_type">
    <option value="">Select Module Type</option>
    <?php foreach($modules as $module_type) {?>
    <option value="<?= $module_type->id?>"><?= $module_type->name?></option>
    <?php }?>
    </select>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" class="btn btn-success" id="create-feature" value="Create Feature" /></td>
  </tr>
</table>
</div>
</div>
<script type="text/javascript">
$('#create-module').click(function () {	
	if(!$('.module_name').val())
	{
	alert('Name Feild is Required');	
		$('.module_name').focus();
	}
	else if(!$('.module_desc').val())
	{
	alert('Description Feild is Required');	
		$('.module_desc').focus();
	}
	else if(!$('.module_price').val())
	{
	alert('Price Feild is Required');	
		$('.module_price').focus();
	}
	else if(!$('.module_type').val())
	{
	alert('Type Feild is Required');	
	$('.module_type').focus();
	}
	else {
	var module_name = $('.module_name').val();
	var module_desc = $('.module_desc').val();
	var module_price = $('.module_price').val();
	var module_type = $('.module_type').val();
	
	
	$.post('<?= site_url('user/proposal/create_module');?>',{module_name : module_name , module_desc : module_desc , module_price : module_price, module_type : module_type}, function(data) {
	 //alert(data)
	 $('.module_name').val("");
	 $('.module_desc').val("");
	 $('.module_price').val("");
	 $('.module_type').val("");
	  location.reload(); 
	 });
	}
	
	})
	
	// for features
	
	$('#create-feature').click(function () {	
	if(!$('.feature_name').val())
	{
	alert('Name Feild is Required');	
		$('.feature_name').focus();
	}
	else if(!$('.feature_desc').val())
	{
	alert('Description Feild is Required');	
		$('.feature_desc').focus();
	}
	else if(!$('.feature_price').val())
	{
	alert('Price Feild is Required');	
		$('.feature_price').focus();
	}
	else if(!$('.feature_type').val())
	{
	alert('Type Feild is Required');	
	$('.feature_type').focus();
	}
	else {
	var feature_name = $('.feature_name').val();
	var feature_desc = $('.feature_desc').val();
	var feature_price = $('.feature_price').val();
	var feature_type = $('.feature_type').val();
	

	$.post('<?= site_url('user/proposal/create_feature');?>',{feature_name : feature_name , feature_desc : feature_desc , feature_price : feature_price, feature_type : feature_type}, function(data) {
	alert(data)
	 $('.feature_name').val("");
	 $('.feature_desc').val("");
	 $('.feature_price').val("");
	 $('.feature_type').val("");
	  location.reload(); 
	 });
	}
	
	})
	
	
</script>